home *** CD-ROM | disk | FTP | other *** search
- class Vector
- {
- var x;
- var y;
- function Vector(i, j)
- {
- this.x = i;
- this.y = j;
- }
- function clone()
- {
- return new Vector(this.x,this.y);
- }
- function magnitude()
- {
- return Math.sqrt(this.x * this.x + this.y * this.y);
- }
- function subtract(v)
- {
- return new Vector(this.x - v.x,this.y - v.y);
- }
- function normalize(l)
- {
- l = l !== undefined ? l : 1;
- var _loc2_ = this.magnitude() / l;
- this.x /= _loc2_;
- this.y /= _loc2_;
- }
- static function vectDist(v1, v2)
- {
- return Math.sqrt((v2.x - v1.x) * (v2.x - v1.x) + (v2.y - v1.y) * (v2.y - v1.y));
- }
- static function cpol(v1, v2, v3)
- {
- var _loc4_ = (v1.x - v2.x) * (v1.x - v2.x) + (v1.y - v2.y) * (v1.y - v2.y);
- var _loc3_ = ((v3.x - v1.x) * (v2.x - v1.x) + (v3.y - v1.y) * (v2.y - v1.y)) / _loc4_;
- return new Vector(v1.x + _loc3_ * (v2.x - v1.x),v1.y + _loc3_ * (v2.y - v1.y));
- }
- static function lineIntersection(av1, av2, bv1, bv2)
- {
- var _loc5_ = av2.y - av1.y;
- var _loc3_ = av1.x - av2.x;
- var _loc9_ = _loc5_ * av1.x + _loc3_ * av1.y;
- var _loc4_ = bv2.y - bv1.y;
- var _loc2_ = bv1.x - bv2.x;
- var _loc8_ = _loc4_ * bv1.x + _loc2_ * bv1.y;
- var _loc1_ = _loc5_ * _loc2_ - _loc4_ * _loc3_;
- if(_loc1_ == 0)
- {
- return undefined;
- }
- return new Vector((_loc2_ * _loc9_ - _loc3_ * _loc8_) / _loc1_,(_loc5_ * _loc8_ - _loc4_ * _loc9_) / _loc1_);
- }
- static function fromPolar(a, m)
- {
- return new Vector(m * Math.cos(a),m * Math.sin(a));
- }
- function toString()
- {
- return "( x=" + this.x + ", y=" + this.y + ")";
- }
- function mark(mc, col)
- {
- col = col != undefined ? col : 16711680;
- mc.lineStyle(0,col);
- mc.moveTo(this.x - 2,this.y - 2);
- mc.lineTo(this.x + 2,this.y + 2);
- mc.moveTo(this.x - 2,this.y + 2);
- mc.lineTo(this.x + 2,this.y - 2);
- }
- }
-